package com.ihg.hiex.entity.user;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.demo2do.core.utils.DateUtils;
import com.ihg.hiex.entity.data.ElearningSource;

/**
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "assessor_e_learning")
public class AssessorElearning {
    
    @Id
    @GeneratedValue
    private Long id;
    
    private String courseId;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Assessor assessor;
    
    private Long sessionId;
    
    // 课程地址
    private String path;
    
    // 课程状态
    private String status;
    
    private String isExit;
    
    private String entry;
    
    private String masterScore;
    
    private int sequence;
    
    private String type;
    
    @Temporal(TemporalType.TIME)
    private Date totalTime;
    
    private int score;
    
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public AssessorElearning() {
    }
    
    /**
     * 
     * @param elearningSource
     * @param assessor
     * @param courseId
     */
    public AssessorElearning(ElearningSource elearningSource, Assessor assessor, String courseId) {
        this.masterScore = elearningSource.getMasteryScore();
        this.type = elearningSource.getType();
        this.sequence = elearningSource.getSequence();
        this.path = elearningSource.getPath();
        this.courseId = courseId;
        this.assessor = assessor;
        this.sessionId = assessor.getCurrentSessionId();
    }
    
    /**
     * 
     * @return
     */
    public AssessorElearning init() {
        this.status = "incompleted";
        this.totalTime = DateUtils.parseDate("00:00:00", "HH:mm:SS");
        this.disabled = false;
        return this;
    }
    
    /**
     * 
     * @param totalTime
     * @param lessonStatus
     * @return
     */
    public AssessorElearning finish(Date totalTime, String lessonStatus) {
        this.totalTime = totalTime;
        this.score = 0;
        this.status = lessonStatus;
//        
//        if(this.score >= Integer.parseInt(this.masterScore)) {
//            this.status = "passed";
//        } else {
//            this.status = "failed";
//        }
        
        return this;
    }
    
    /**
     * 
     * @param status
     * @param isExit
     * @param entry
     * @return
     */
    public AssessorElearning udpate(String status, String isExit, String entry) {
        this.isExit = isExit;
        
        if(this.score >= Integer.parseInt(this.masterScore)) {
            this.status = "passed";
        } else {
            this.status = status;
        }
        
        this.entry = entry;
        
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the courseId
     */
    public String getCourseId() {
        return courseId;
    }

    /**
     * @return the assessor
     */
    public Assessor getAssessor() {
        return assessor;
    }

    /**
     * @return the sessionId
     */
    public Long getSessionId() {
        return sessionId;
    }

    /**
     * @return the path
     */
    public String getPath() {
        return path;
    }

    /**
     * @return the status
     */
    public String getStatus() {
        return status;
    }

    /**
     * @return the isExit
     */
    public String getIsExit() {
        return isExit;
    }

    /**
     * @return the entry
     */
    public String getEntry() {
        return entry;
    }

    /**
     * @return the masterScore
     */
    public String getMasterScore() {
        return masterScore;
    }

    /**
     * @return the sequence
     */
    public int getSequence() {
        return sequence;
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }

    /**
     * @return the totalTime
     */
    public Date getTotalTime() {
        return totalTime;
    }

    /**
     * @return the score
     */
    public int getScore() {
        return score;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param courseId the courseId to set
     */
    public void setCourseId(String courseId) {
        this.courseId = courseId;
    }

    /**
     * @param assessor the assessor to set
     */
    public void setAssessor(Assessor assessor) {
        this.assessor = assessor;
    }

    /**
     * @param sessionId the sessionId to set
     */
    public void setSessionId(Long sessionId) {
        this.sessionId = sessionId;
    }

    /**
     * @param path the path to set
     */
    public void setPath(String path) {
        this.path = path;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(String status) {
        this.status = status;
    }

    /**
     * @param isExit the isExit to set
     */
    public void setIsExit(String isExit) {
        this.isExit = isExit;
    }

    /**
     * @param entry the entry to set
     */
    public void setEntry(String entry) {
        this.entry = entry;
    }

    /**
     * @param masterScore the masterScore to set
     */
    public void setMasterScore(String masterScore) {
        this.masterScore = masterScore;
    }

    /**
     * @param sequence the sequence to set
     */
    public void setSequence(int sequence) {
        this.sequence = sequence;
    }

    /**
     * @param type the type to set
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * @param totalTime the totalTime to set
     */
    public void setTotalTime(Date totalTime) {
        this.totalTime = totalTime;
    }

    /**
     * @param score the score to set
     */
    public void setScore(int score) {
        this.score = score;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
}
